package com.service;

import com.model.LeaveRequest;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;

@Service
public class LeaveRequestServiceImpl implements LeaveRequestService {
    private final AtomicLong counter = new AtomicLong();
    private final List<LeaveRequest> leaveRequests = new ArrayList<>();

    @Override
    public LeaveRequest createLeaveRequest(Long studentId, String reason) {
        LeaveRequest leaveRequest = new LeaveRequest();
        leaveRequest.setId(counter.incrementAndGet());
        leaveRequest.setStudentId(studentId);
        leaveRequest.setReason(reason);
        leaveRequest.setStatus("Pending");
        leaveRequests.add(leaveRequest);
        return leaveRequest;
    }

    @Override
    public Optional<LeaveRequest> getLeaveRequestById(Long id) {
        return leaveRequests.stream().filter(lr -> lr.getId().equals(id)).findFirst();
    }
}
